/**
 * 
 */
package com.lehecai.core.api.event;

import com.lehecai.core.YesNoStatus;
import com.lehecai.core.api.AbstractApiResultBean;
import com.lehecai.core.event.EventLogStatus;
import com.lehecai.core.util.CoreDateUtils;
import net.sf.json.JSONArray;
import net.sf.json.JSONObject;
import org.apache.commons.lang.StringUtils;

import java.util.ArrayList;
import java.util.Date;
import java.util.Iterator;
import java.util.List;

/**
 * 领取资格
 * @author He Wang
 */
public class EventQualify extends AbstractApiResultBean {
	public static final String QUERY_UID = "uid";
	public static final String QUERY_EVENT_ID = "event_id";
	public static final String QUERY_TIMELINE="timeline";
	
	public static final String SET_EVENT_ID = "event_id";
	public static final String SET_STATUS = "status";
	public static final String SET_NUM_LIMITED = "num_limited";
	public static final String SET_OPEN_TIME = "open_time";
	public static final String SET_DATE_TIME = "date_time";

	private Integer eventId;	//活动编码
	private YesNoStatus status;//是否开启
	private Integer numLimited;
	private String openTimePeriod;//开放时间段
	private String dateTimePeriod;//领取时间段
	private Date dateTimeStart;
	private Date dateTimeEnd;

	private Date eventStartTime;    //活动起始时间
	private Date eventEndTime;      //活动结束时间
	private Date timeline;          //活动创建时间
	private Integer numReleased;//已领取个数

	public static EventQualify convertFromJSONObject(JSONObject object) {
		if (object == null) {
			return null;
		}
		EventQualify eventQualify = new EventQualify();
		eventQualify.eventId = getInt(object, "event_id");
		eventQualify.numLimited = getInt(object, "num_limited");
		eventQualify.status = YesNoStatus.getItem(getInt(object, "status"));
		eventQualify.openTimePeriod = getString(object, "open_time");
		eventQualify.dateTimePeriod = getString(object, "date_time");
		if (StringUtils.isNotEmpty(eventQualify.dateTimePeriod) && StringUtils.split(eventQualify.dateTimePeriod, "|").length == 2) {
			eventQualify.dateTimeStart = CoreDateUtils.parseDate(StringUtils.split(eventQualify.dateTimePeriod, "|")[0], CoreDateUtils.DATETIME);
			eventQualify.dateTimeEnd = CoreDateUtils.parseDate(StringUtils.split(eventQualify.dateTimePeriod, "|")[1], CoreDateUtils.DATETIME);
		}
		eventQualify.numReleased = getInt(object, "num_released");
		return eventQualify;
	}
	
	public static List<EventQualify> convertFromJSONArray(JSONArray array) {
		if (array == null) {
			return null;
		}
		List<EventQualify> list = new ArrayList<EventQualify>();
		for (Iterator<?> iterator = array.iterator(); iterator.hasNext();) {
			JSONObject object = (JSONObject) iterator.next();
			list.add(convertFromJSONObject(object));
		}
		return list;
	}

	public Integer getEventId() {
		return eventId;
	}

	public void setEventId(Integer eventId) {
		this.eventId = eventId;
	}

	public YesNoStatus getStatus() {
		return status;
	}

	public void setStatus(YesNoStatus status) {
		this.status = status;
	}

	public Integer getNumLimited() {
		return numLimited;
	}

	public void setNumLimited(Integer numLimited) {
		this.numLimited = numLimited;
	}

	public String getOpenTimePeriod() {
		return openTimePeriod;
	}

	public void setOpenTimePeriod(String openTimePeriod) {
		this.openTimePeriod = openTimePeriod;
	}

	public String getDateTimePeriod() {
		return dateTimePeriod;
	}

	public void setDateTimePeriod(String dateTimePeriod) {
		this.dateTimePeriod = dateTimePeriod;
	}

	public Date getDateTimeStart() {
		return dateTimeStart;
	}

	public void setDateTimeStart(Date dateTimeStart) {
		this.dateTimeStart = dateTimeStart;
	}

	public Date getDateTimeEnd() {
		return dateTimeEnd;
	}

	public void setDateTimeEnd(Date dateTimeEnd) {
		this.dateTimeEnd = dateTimeEnd;
	}

	public Date getEventStartTime() {
		return eventStartTime;
	}

	public void setEventStartTime(Date eventStartTime) {
		this.eventStartTime = eventStartTime;
	}

	public Date getEventEndTime() {
		return eventEndTime;
	}

	public void setEventEndTime(Date eventEndTime) {
		this.eventEndTime = eventEndTime;
	}

	public Date getTimeline() {
		return timeline;
	}

	public void setTimeline(Date timeline) {
		this.timeline = timeline;
	}

	public Integer getNumReleased() {
		return numReleased;
	}

	public void setNumReleased(Integer numReleased) {
		this.numReleased = numReleased;
	}
}
